<?php
  
  require_once('./includes/db.php');
  $msg = '';

  unset($_POST['cpassword']);
  $_POST['lang'] = implode(',',$_POST['lang']);
  $_POST['hobbies'] = implode(',',$_POST['hobbies']);
  $_POST['avatar'] = $_FILES['avatar']['name'];
  $_POST['added_date'] = date('Y-m-d H:i:s');
  $_POST['status'] = '1';
  
  $_POST = arrayCleanup($_POST);
    
  pr($_POST);
  pr($_FILES);
  #########################################
  $allowedExtn = array('jpg','jpeg','png');
  $allowedSize = 1.0;// in MB
  $uploadFlag = true;
   
  if(is_uploaded_file($_FILES['avatar']['tmp_name']))
  {
    $infoArr = pathinfo($_FILES['avatar']['name']);
    $extn = $infoArr['extension'];
    if(!in_array($extn,$allowedExtn )) {
      $uploadFlag = false;
      $msg = 'Please upload file with valid extension';
    } else {
      $uploadSize = $allowedSize * 1024 * 1024;    
      if($_FILES['avatar']['size'] > $uploadSize) {
        $uploadFlag = false;
        $msg = "Please upload file with max $allowedSize MB";
      }       
    }    
  } else {// end if(is_uploaded_file)
    $uploadFlag = false;
    $msg = "Upload error!! Please try again later.<br>
    Please upload file with max $allowedSize MB.";
  }
  if($uploadFlag == false){
    pr($msg);    
  } else {
    $fileName = $_FILES['avatar']['name'];
    $src =  $_FILES['avatar']['tmp_name'];
    $fileName  = date('ymdHis').'_'.uniqid().'_'.$fileName;
    $dest = "uploads/$fileName";
    move_uploaded_file($src, $dest);    
  }
  #######################################
 // $id = insert('users',$_POST);
 // echo "Record Inserted on id $id";
  

